<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Rule Family</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Rule Family' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">assertions</a></li><li><a href="index.html#5">Chapter 5: Imperative Code</a></li><li><b>Rule Family</b></li></ul></div>
<p class="purpose">Imperative definitions of rules.</p>

<ul class="toc"><li><a href="5-rf.html#SP1">&#167;1. Introduction</a></li><li><a href="5-rf.html#SP4">&#167;4. Identification</a></li><li><a href="5-rf.html#SP6">&#167;6. Assessment</a></li><li><a href="5-rf.html#SP11">&#167;11. Runtime context data</a></li><li><a href="5-rf.html#SP16">&#167;16. Compilation</a></li><li><a href="5-rf.html#SP17">&#167;17. Miscellaneous access functions</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Introduction.</b>This family handles definitions of rules which give explicit Inform 7
source text to show what they do. (It's also possible to create rules which
are implemented by Inter-level functions only, and those do not fall under
this section, because they have no <a href="5-id.html#SP1" class="internal">imperative_defn</a>.) For example:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Every</span><span class="plain-syntax"> </span><span class="identifier-syntax">turn</span><span class="plain-syntax">:</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">say</span><span class="plain-syntax"> </span><span class="string-syntax">"The grandfather clock ticks reprovingly."</span>
</pre>
<p class="commentary">Some rules have names, some do not; some indicate explicitly what rulebook
they belong to, and others are placed in rulebooks with separate sentences.
So there's quite a lot to do.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">; </span><span class="comment-syntax"> "Before taking a container, ..."</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::create_family</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::create_family</span></span>:<br/>Imperative Definition Families - <a href="5-idf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax"> = </span><a href="5-idf.html#SP2" class="function-link"><span class="function-syntax">ImperativeDefinitionFamilies::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"rule-idf"</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">, </span><span class="constant-syntax">IDENTIFY_IMP_DEFN_MTID</span><span class="plain-syntax">, </span><a href="5-rf.html#SP5" class="function-link"><span class="function-syntax">RuleFamily::identify</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">, </span><span class="constant-syntax">ASSESS_IMP_DEFN_MTID</span><span class="plain-syntax">, </span><a href="5-rf.html#SP7" class="function-link"><span class="function-syntax">RuleFamily::assess</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">, </span><span class="constant-syntax">ASSESSMENT_COMPLETE_IMP_DEFN_MTID</span><span class="plain-syntax">, </span><a href="5-rf.html#SP10" class="function-link"><span class="function-syntax">RuleFamily::assessment_complete</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">, </span><span class="constant-syntax">ALLOWS_RULE_ONLY_PHRASES_IMP_DEFN_MTID</span><span class="plain-syntax">, </span><a href="5-rf.html#SP17" class="function-link"><span class="function-syntax">RuleFamily::allows_rule_only</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">, </span><span class="constant-syntax">GIVEN_BODY_IMP_DEFN_MTID</span><span class="plain-syntax">, </span><a href="5-rf.html#SP8" class="function-link"><span class="function-syntax">RuleFamily::given_body</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">, </span><span class="constant-syntax">TO_RCD_IMP_DEFN_MTID</span><span class="plain-syntax">, </span><a href="5-rf.html#SP11" class="function-link"><span class="function-syntax">RuleFamily::to_rcd</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">, </span><span class="constant-syntax">COMPILE_IMP_DEFN_MTID</span><span class="plain-syntax">, </span><a href="5-rf.html#SP16" class="function-link"><span class="function-syntax">RuleFamily::compile</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>Each family member gets one of the following. In splitting up preambles,
the "usage preamble" is the part indicating when the rule should happen, and
this is divided up into smaller excerpts of text, as in the following examples:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="identifier-syntax">instead</span><span class="plain-syntax">    </span><span class="identifier-syntax">of</span><span class="plain-syntax">          </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> </span><span class="identifier-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">dropping</span><span class="plain-syntax"> </span><span class="identifier-syntax">when</span><span class="plain-syntax"> </span><span class="identifier-syntax">Miss</span><span class="plain-syntax"> </span><span class="identifier-syntax">Bianca</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">Embassy:</span>
<span class="plain-syntax">&lt;---------------------------- </span><span class="identifier-syntax">usage_preamble</span><span class="plain-syntax"> -----------------------------------&gt;</span>
<span class="plain-syntax">     &lt;- </span><span class="identifier-syntax">stem</span><span class="plain-syntax"> ----&gt;          &lt;------------------ </span><span class="identifier-syntax">applicability</span><span class="plain-syntax"> ------------------&gt;</span>
<span class="plain-syntax">     &lt;- </span><span class="identifier-syntax">ps</span><span class="plain-syntax"> -&gt;   &lt;- </span><span class="identifier-syntax">bud</span><span class="plain-syntax"> -&gt;   &lt;--- </span><span class="identifier-syntax">prewhile</span><span class="plain-syntax"> ---&gt;      &lt;-------- </span><span class="identifier-syntax">whenwhile</span><span class="plain-syntax"> --------&gt;</span>

<span class="identifier-syntax">after</span><span class="plain-syntax"> </span><span class="identifier-syntax">examining</span><span class="plain-syntax">    </span><span class="identifier-syntax">an</span><span class="plain-syntax"> </span><span class="identifier-syntax">open</span><span class="plain-syntax"> </span><span class="identifier-syntax">door</span><span class="plain-syntax"> </span><span class="identifier-syntax">during</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">Hurricane</span><span class="plain-syntax"> (</span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">exit</span><span class="plain-syntax"> </span><span class="identifier-syntax">hunting</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule</span><span class="plain-syntax">):</span>
<span class="plain-syntax">&lt;----------------- </span><span class="identifier-syntax">usage</span><span class="plain-syntax"> </span><span class="identifier-syntax">preamble</span><span class="plain-syntax"> -----------------&gt;              &lt;- </span><span class="reserved-syntax">const</span><span class="plain-syntax"> </span><span class="identifier-syntax">name</span><span class="plain-syntax"> --&gt;</span>
<span class="plain-syntax">&lt;---- </span><span class="identifier-syntax">stem</span><span class="plain-syntax"> -----&gt;  &lt;-- </span><span class="identifier-syntax">appl</span><span class="plain-syntax"> --&gt;        &lt;- </span><span class="identifier-syntax">during</span><span class="plain-syntax"> --&gt;</span>
<span class="plain-syntax">&lt;- </span><span class="identifier-syntax">pruned</span><span class="plain-syntax"> </span><span class="identifier-syntax">stem</span><span class="plain-syntax"> -&gt;  &lt;-- </span><span class="identifier-syntax">pw</span><span class="plain-syntax"> ----&gt;</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">usage_preamble</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">pruned_stem</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">constant_name</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">prewhile_applicability</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">applicability</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">whenwhile</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">during_spec</span><span class="plain-syntax">; </span><span class="comment-syntax"> what scene is currently under way</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">not_in_rulebook</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> *</span><span class="identifier-syntax">defines</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">rulebook</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owning_rulebook</span><span class="plain-syntax">; </span><span class="comment-syntax"> the primary booking for the phrase will be here</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">owning_rulebook_placement</span><span class="plain-syntax">; </span><span class="comment-syntax"> ...and with this placement value: see Rulebooks</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">permit_all_outcomes</span><span class="plain-syntax">; </span><span class="comment-syntax"> waive the usual restrictions on rule outcomes</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">feature_rfd</span><span class="plain-syntax">[</span><span class="identifier-syntax">MAX_COMPILER_FEATURES</span><span class="plain-syntax">]; </span><span class="comment-syntax"> storage for features to attach, if they want to</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="function-syntax">RuleFamily::new_data</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::new_data</span></span>:<br/><a href="5-rf.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">pruned_stem</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">constant_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">usage_preamble</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">prewhile_applicability</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">during_spec</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">not_in_rulebook</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">defines</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook_placement</span><span class="plain-syntax"> = </span><span class="constant-syntax">MIDDLE_PLACEMENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">permit_all_outcomes</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">MAX_COMPILER_FEATURES</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">feature_rfd</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure rule_family_data is accessed in 5/tpf and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>These two macros provide access to feature-specific rule family data:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="identifier-syntax">RFD_FEATURE_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    ((</span><span class="identifier-syntax">id</span><span class="plain-syntax">##</span><span class="identifier-syntax">_rfd_data</span><span class="plain-syntax"> *) </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">feature_rfd</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">##</span><span class="identifier-syntax">_feature</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">])</span>
<span class="definition-keyword">define</span> <span class="identifier-syntax">CREATE_RFD_FEATURE_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">, </span><span class="identifier-syntax">creator</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    (</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">)-&gt;</span><span class="element-syntax">feature_rfd</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">##</span><span class="identifier-syntax">_feature</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">] = (</span><span class="reserved-syntax">void</span><span class="plain-syntax"> *) (</span><span class="identifier-syntax">creator</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">));</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Identification.</b>We are going to claim as our own any definition whose name matches the
following nonterminal &mdash; and because of the last production, this will always
happen. (That's why it is important that we are the last family to claim.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;rule-preamble&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> {... </span><span class="reserved-syntax">rule</span><span class="plain-syntax">} |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> ... </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> ... </span><span class="identifier-syntax">rules</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    ... ( </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> {... </span><span class="reserved-syntax">rule</span><span class="plain-syntax">} ) |</span>
<span class="plain-syntax">    ... ( </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> ) |</span>
<span class="plain-syntax">    ... ( </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> ... </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> ) |</span>
<span class="plain-syntax">    ... ( </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> ... </span><span class="identifier-syntax">rules</span><span class="plain-syntax"> ) |</span>
<span class="plain-syntax">    ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4_1" class="paragraph-anchor"></a><b>&#167;4.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_NamelessRule problem</span><span class="named-paragraph-number">4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_NamelessRule</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"there are many rules in Inform"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"so you need to give a name: 'this is the abolish dancing rule', say, "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"not just 'this is the rule'."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, - }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP4">&#167;4</a> (twice).</li></ul>
<p class="commentary firstcommentary"><a id="SP4_2" class="paragraph-anchor"></a><b>&#167;4.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_UnarticledRule problem</span><span class="named-paragraph-number">4.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_UnarticledRule</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"a rule must be given a definite name"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"which begins with 'the', just to emphasise that it is the only one "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"with this name: 'this is the promote dancing rule', say, not just "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'this is promote dancing rule'."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, - }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP4">&#167;4</a> (twice).</li></ul>
<p class="commentary firstcommentary"><a id="SP4_3" class="paragraph-anchor"></a><b>&#167;4.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_PluralisedRule problem</span><span class="named-paragraph-number">4.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_PluralisedRule</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"a rule must be given a definite name ending in 'rule' not 'rules'"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"since the plural is only used for rulebooks, which can of course "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"contain many rules at once."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, - }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP4">&#167;4</a> (twice).</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Forms 1 and 2 give a rule name; forms 2 and 3 say which rulebook it goes into.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::identify</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::identify</span></span>:<br/><a href="5-rf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">self</span><span class="plain-syntax">, </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">at</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;rule-preamble&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">form</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><a href="5-rf.html#SP2" class="function-link"><span class="function-syntax">RuleFamily::new_data</span></a><span class="plain-syntax">();</span>

<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">form</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">not_in_rulebook</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax"> = </span><span class="identifier-syntax">STORE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">form</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">RW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rule-preamble&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="6-rls.html#SP3" class="function-link"><span class="function-syntax">Rules::vet_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">RW</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">constant_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><a href="6-rls.html#SP2" class="function-link"><span class="function-syntax">Rules::obtain</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">RW</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">form</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">RW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rule-preamble&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="6-rls.html#SP3" class="function-link"><span class="function-syntax">Rules::vet_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">RW</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">constant_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><a href="6-rls.html#SP2" class="function-link"><span class="function-syntax">Rules::obtain</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">RW</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">form</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">form</span><span class="plain-syntax"> == </span><span class="constant-syntax">3</span><span class="plain-syntax">)) </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">usage_preamble</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rule-preamble&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>

<span class="plain-syntax">        </span><span class="identifier-syntax">PluginCalls::new_rule_defn_notify</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Assessment.</b>Now we take a closer look at the rule preamble.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;rule-preamble-fine&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;rule-preamble-finer&gt;</span><span class="plain-syntax"> </span><span class="identifier-syntax">during</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;s-scene-description&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;rule-preamble-finer&gt;</span>

<span class="function-syntax">&lt;rule-preamble-finer&gt;</span>
<span class="plain-syntax">    {</span><span class="function-syntax">&lt;rulebook-stem-embellished&gt;</span><span class="plain-syntax">} {</span><span class="identifier-syntax">when</span><span class="plain-syntax">/</span><span class="reserved-syntax">while</span><span class="plain-syntax"> ...} |</span>
<span class="plain-syntax">    {</span><span class="function-syntax">&lt;rulebook-stem-embellished&gt;</span><span class="plain-syntax">} |</span>
<span class="plain-syntax">    ...</span>

<span class="function-syntax">&lt;rulebook-stem-embellished&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;rulebook-stem&gt;</span><span class="plain-syntax"> *** |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;article&gt;</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;rulebook-stem&gt;</span><span class="plain-syntax"> *** |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;article&gt;</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;rulebook-stem&gt;</span><span class="plain-syntax"> *** |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;rulebook-stem&gt;</span><span class="plain-syntax"> *** |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;rulebook-stem&gt;</span><span class="plain-syntax"> ***</span>

<span class="function-syntax">&lt;rulebook-bud&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">of</span><span class="plain-syntax">/</span><span class="reserved-syntax">for</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="identifier-syntax">about</span><span class="plain-syntax">/</span><span class="reserved-syntax">for</span><span class="plain-syntax">/</span><span class="identifier-syntax">on</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule</span>

<span class="function-syntax">&lt;unrecognised-rule-stem-diagnosis&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">when</span><span class="plain-syntax"> *** |</span>
<span class="plain-syntax">    ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6_1" class="paragraph-anchor"></a><b>&#167;6.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_BadRulePreambleWhen</span><span class="named-paragraph-number">6.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_BadRulePreambleWhen</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"The punctuation makes me think %1 should be a definition of a phrase or a rule, "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"but it doesn't begin as it should, with either 'To' (e.g. 'To flood the riverplain:'), "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'Definition:', a name for a rule (e.g. 'This is the devilishly cunning rule:'), "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'At' plus a time (e.g. 'At 11:12 PM:' or 'At the time when the clock chimes:') or "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"the name of a rulebook. %P"</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Perhaps you meant to say that something would only happen when some condition held. "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Inform often allows this, but the 'when...' part tends to be at the end, not up "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"front - for instance, 'Understand \"blue\" as the deep crevasse when the location "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"is the South Pole.'"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP6">&#167;6</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP6_2" class="paragraph-anchor"></a><b>&#167;6.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_BadRulePreamble</span><span class="named-paragraph-number">6.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_BadRulePreamble</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"the punctuation here ':' makes me think this should be a definition of a phrase "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"and it doesn't begin as it should"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"with either 'To' (e.g. 'To flood the riverplain:'), 'Definition:', a name for a "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"rule (e.g. 'This is the devilishly cunning rule:'), 'At' plus a time (e.g. 'At "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"11:12 PM:' or 'At the time when the clock chimes') or the name of a rulebook, "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"possibly followed by some description of the action or value to apply to (e.g. "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'Instead of taking something:' or 'Every turn:')."</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP6">&#167;6</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>The crucial nonterminal in the above grammar is &lt;rulebook-stem&gt;, which tries
to make the longest match it can of a rulebook name; if it matches successfully,
then calling <span class="extract"><span class="extract-syntax">Rulebooks::match</span></span> produces a detailed rundown of its findings,
which are too elaborate to pass back in a simple pointer.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::assess</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::assess</span></span>:<br/><a href="5-rf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">self</span><span class="plain-syntax">, </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">not_in_rulebook</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">usage_preamble</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="function-syntax">&lt;rule-preamble-fine&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">during_spec</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">has_when</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rulebook_match</span><span class="plain-syntax"> *</span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax"> = </span><a href="6-rlb.html#SP19" class="function-link"><span class="function-syntax">Rulebooks::match</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rule-preamble-finer&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">has_when</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NOT_APPLICABLE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="function-syntax">&lt;unrecognised-rule-stem-diagnosis&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">has_when</span><span class="plain-syntax">) </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rule-preamble-finer&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">during_spec</span><span class="plain-syntax"> = </span><span class="identifier-syntax">during_spec</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">matched_rulebook</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook_placement</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement_requested</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP7_1" class="named-paragraph-link"><span class="named-paragraph">Disallow the definite article for middling rules</span><span class="named-paragraph-number">7.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP7_2" class="named-paragraph-link"><span class="named-paragraph">Cut off the bud from the stem</span><span class="named-paragraph-number">7.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP7_3" class="named-paragraph-link"><span class="named-paragraph">Merge the when/while text back into applicability, for actions</span><span class="named-paragraph-number">7.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">pruned_stem</span><span class="plain-syntax"> = </span><span class="identifier-syntax">W</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7_1" class="paragraph-anchor"></a><b>&#167;7.1. </b>This is a super-pedantic problem message, and might cause problems in languages
other than English.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Disallow the definite article for middling rules</span><span class="named-paragraph-number">7.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">article_used</span><span class="plain-syntax"> == </span><span class="identifier-syntax">definite_article</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement_requested</span><span class="plain-syntax"> == </span><span class="constant-syntax">MIDDLE_PLACEMENT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_RuleWithDefiniteArticle</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="string-syntax">"a rulebook can contain any number of rules"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"so (e.g.) 'the before rule: ...' is disallowed; you should write 'a before "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"rule: ...' instead."</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP7">&#167;7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP7_2" class="paragraph-anchor"></a><b>&#167;7.2. </b>The bud is not always present at all, and need not always be at the end of the stem,
so we have to be very careful:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Cut off the bud from the stem</span><span class="named-paragraph-number">7.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rulebook-stem-embellished&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">b1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">), </span><span class="identifier-syntax">b2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::last_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">b1</span><span class="plain-syntax"> == -1) || (</span><span class="identifier-syntax">b1</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">b2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">b1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_from</span><span class="plain-syntax"> + </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">advance_words</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">b2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_from</span><span class="plain-syntax"> + </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">advance_words</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">b2</span><span class="plain-syntax"> -= </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tail_words</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">b1</span><span class="plain-syntax">, </span><span class="identifier-syntax">b2</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">advance_words</span><span class="plain-syntax"> != </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_length</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (!((</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">)) &amp;&amp; (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::from</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">, </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_from</span><span class="plain-syntax"> + </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_length</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">) </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">) </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">) </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">advance_words</span><span class="plain-syntax"> != </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_length</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::from</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">, </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_from</span><span class="plain-syntax"> + </span><span class="identifier-syntax">parsed_rm</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">match_length</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">) </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;rulebook-bud&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">APPW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BUDW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">APPW</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax"> = </span><span class="identifier-syntax">APPW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">prewhile_applicability</span><span class="plain-syntax"> = </span><span class="identifier-syntax">APPW</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP7">&#167;7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP7_3" class="paragraph-anchor"></a><b>&#167;7.3. </b>This unobvious manoeuvre puts the when/while text back again, so that:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="identifier-syntax">instead</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> </span><span class="identifier-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">dropping</span><span class="plain-syntax"> </span><span class="identifier-syntax">when</span><span class="plain-syntax"> </span><span class="identifier-syntax">Miss</span><span class="plain-syntax"> </span><span class="identifier-syntax">Bianca</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">Embassy:</span>
<span class="plain-syntax">                &lt;----- </span><span class="identifier-syntax">appl</span><span class="plain-syntax"> -----&gt; &lt;---------- </span><span class="identifier-syntax">whenwhile</span><span class="plain-syntax"> -----------&gt;</span>
</pre>
<p class="commentary">becomes:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">rule</span><span class="plain-syntax"> </span><span class="identifier-syntax">instead</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> </span><span class="identifier-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">dropping</span><span class="plain-syntax"> </span><span class="identifier-syntax">when</span><span class="plain-syntax"> </span><span class="identifier-syntax">Miss</span><span class="plain-syntax"> </span><span class="identifier-syntax">Bianca</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">Embassy:</span>
<span class="plain-syntax">                &lt;----- </span><span class="identifier-syntax">appl</span><span class="plain-syntax"> ----------------------------------------&gt;</span>
</pre>
<p class="commentary">This is done only where we now know that the stem specified a rulebook based
on actions, and the reason it's done is that action applicabilities are parsed
with a grammar much more sensitive to ambiguities, and in which "when..."
clauses are therefore better recognised.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Merge the when/while text back into applicability, for actions</span><span class="named-paragraph-number">7.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="6-rlb.html#SP12" class="function-link"><span class="function-syntax">Rulebooks::runs_during_activities</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="6-rlb.html#SP4" class="function-link"><span class="function-syntax">Rulebooks::action_focus</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">),</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Wordings::last_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP7">&#167;7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>Every rule corresponds to a <span class="extract"><span class="extract-syntax">rule</span></span> structure. If the rule is an anonymous
one, such as:
</p>

<blockquote>
    <p>Instead of jumping: say "Don't."</p>
</blockquote>

<p class="commentary">then we need to call <span class="extract"><span class="extract-syntax">Rules::obtain</span></span> to create a nameless <span class="extract"><span class="extract-syntax">rule</span></span> structure
to be connected to it. But if the phrase has an explicit name:
</p>

<blockquote>
    <p>Instead of swimming (this is the avoid water rule): say "Don't."</p>
</blockquote>

<p class="commentary">then we have a predeclared rule called "avoid water rule" already, so we
connect this existing one to the phrase.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::given_body</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::given_body</span></span>:<br/><a href="5-rf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">self</span><span class="plain-syntax">, </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP8_1" class="named-paragraph-link"><span class="named-paragraph">Set R to a corresponding rule structure</span><span class="named-paragraph-number">8.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">defines</span><span class="plain-syntax"> = </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">body_of_defn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">compilation_data</span><span class="plain-syntax">.</span><span class="identifier-syntax">compile_with_run_time_debugging</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="5-ptd.html#SP10" class="function-link"><span class="function-syntax">IDTypeData::set_mor</span></a><span class="plain-syntax">(&amp;(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">body_of_defn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">type_data</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="constant-syntax">DECIDES_NOTHING_AND_RETURNS_MOR</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">not_in_rulebook</span><span class="plain-syntax">) </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">permit_all_outcomes</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8_1" class="paragraph-anchor"></a><b>&#167;8.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Set R to a corresponding rule structure</span><span class="named-paragraph-number">8.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">explicitly</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">constant_name</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Articles::remove_the</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">constant_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">explicitly</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) </span><span class="identifier-syntax">R</span><span class="plain-syntax"> = </span><a href="6-rls.html#SP5" class="function-link"><span class="function-syntax">Rules::by_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP8_1_1" class="named-paragraph-link"><span class="named-paragraph">Check that this isn't duplicating the name of a rule already made</span><span class="named-paragraph-number">8.1.1</span></a></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax"> = </span><a href="6-rls.html#SP2" class="function-link"><span class="function-syntax">Rules::obtain</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">explicitly</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="6-rls.html#SP9" class="function-link"><span class="function-syntax">Rules::set_imperative_definition</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">, </span><span class="identifier-syntax">id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP8_1_2" class="named-paragraph-link"><span class="named-paragraph">Merge the applicability and when/while text for indexing purposes</span><span class="named-paragraph-number">8.1.2</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP8">&#167;8</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP8_1_1" class="paragraph-anchor"></a><b>&#167;8.1.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Check that this isn't duplicating the name of a rule already made</span><span class="named-paragraph-number">8.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">existing_id</span><span class="plain-syntax"> = </span><a href="6-rls.html#SP9" class="function-link"><span class="function-syntax">Rules::get_imperative_definition</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">existing_id</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">existing_id</span><span class="plain-syntax"> != </span><span class="identifier-syntax">id</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_DuplicateRuleName</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"You wrote %1, but this would give a name ('%2') to a "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"new rule which already belongs to an existing one."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP8_1">&#167;8.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP8_1_2" class="paragraph-anchor"></a><b>&#167;8.1.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Merge the applicability and when/while text for indexing purposes</span><span class="named-paragraph-number">8.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">IX</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">) == </span><span class="identifier-syntax">Wordings::last_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">) + </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">IX</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">),</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Wordings::last_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">IX</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RTRules::set_italicised_index_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">, </span><span class="identifier-syntax">IX</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP8_1">&#167;8.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>This is to do with named outcomes of rules, whereby certain outcomes are
normally limited to the use of rules in particular rulebooks.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::outcome_restrictions_waived</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">id_body</span><span class="plain-syntax"> *</span><span class="identifier-syntax">idb</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Functions::defn_being_compiled</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">idb</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">idb</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">head_of_defn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family</span><span class="plain-syntax"> != </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">permit_all_outcomes</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>At the end of the assessment process, we can finally put the rules into their
rulebooks. We make "automatic placements" first &mdash; i.e., those where the usage
preamble specified which rulebook the rule belonged to; and then we make manual
placements, which may move or remove rules already place. See <a href="3-rpr.html" class="internal">Rule Placement Requests</a>
for how sentences specifying this are parsed.
</p>

<pre class="definitions code-font"><span class="definition-keyword">enum</span> <span class="constant-syntax">TRAVERSE_FOR_RULE_FILING_SMFT</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::assessment_complete</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::assessment_complete</span></span>:<br/><a href="5-rf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">self</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family</span><span class="plain-syntax"> == </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">not_in_rulebook</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) </span><a href="6-rls.html#SP17" class="function-link"><span class="function-syntax">Rules::request_automatic_placement</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">defines</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">initial_problem_count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">problem_count</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="6-rb.html#SP6" class="function-link"><span class="function-syntax">RuleBookings::make_automatic_placements</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">initial_problem_count</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">problem_count</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">SyntaxTree::traverse</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><a href="5-rf.html#SP10" class="function-link"><span class="function-syntax">RuleFamily::visit_to_parse_placements</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::visit_to_parse_placements</span><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Node::get_type</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">) == </span><span class="identifier-syntax">SENTENCE_NT</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">p</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Node::get_type</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">) == </span><span class="identifier-syntax">VERB_NT</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">prevailing_mood</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Annotations::read_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">, </span><span class="identifier-syntax">verbal_certainty_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-ptmn.html#SP4" class="function-link"><span class="function-syntax">MajorNodes::try_special_meaning</span></a><span class="plain-syntax">(</span><span class="constant-syntax">TRAVERSE_FOR_RULE_FILING_SMFT</span><span class="plain-syntax">, </span><span class="identifier-syntax">p</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. Runtime context data.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">NAP_problem_explained</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">; </span><span class="comment-syntax"> pertains to Named Action Patterns</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">issuing_ANL_problem</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">; </span><span class="comment-syntax"> pertains to Action Name Lists</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">defective_ANL_clauses</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="comment-syntax"> ditto</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::to_rcd</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::to_rcd</span></span>:<br/><a href="5-rf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">self</span><span class="plain-syntax">, </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">id_runtime_context_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">not_in_rulebook</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1" class="named-paragraph-link"><span class="named-paragraph">Parse the applicability text into the PHRCD</span><span class="named-paragraph-number">11.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">rcd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">activity_context</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Wordings::from</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">, </span><span class="identifier-syntax">Wordings::first_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">) + </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">during_spec</span><span class="plain-syntax">) </span><span class="identifier-syntax">Scenes::set_rcd_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">, </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">during_spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11_1" class="paragraph-anchor"></a><b>&#167;11.1. </b>Here we try the text first without its when clause, then with, and accept
whichever way works.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Parse the applicability text into the PHRCD</span><span class="named-paragraph-number">11.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="6-rlb.html#SP4" class="function-link"><span class="function-syntax">Rulebooks::action_focus</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">save_cs</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ActionRules::set_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">, </span><span class="identifier-syntax">ActionPatterns::parse_action_based</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">save_cs</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ActionRules::get_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">) == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1" class="named-paragraph-link"><span class="named-paragraph">Issue a problem message for a bad action</span><span class="named-paragraph-number">11.1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pk</span><span class="plain-syntax"> = </span><a href="6-rlb.html#SP4" class="function-link"><span class="function-syntax">Rulebooks::get_focus_kind</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ActionRules::set_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">, </span><span class="identifier-syntax">ActionPatterns::parse_parametric</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">, </span><span class="identifier-syntax">pk</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ActionRules::get_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">) == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">F</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::up_to</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">, </span><span class="identifier-syntax">Wordings::last_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">ActionRules::set_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">, </span><span class="identifier-syntax">ActionPatterns::parse_parametric</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">, </span><span class="identifier-syntax">pk</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ActionRules::get_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax"> = </span><span class="identifier-syntax">F</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">whenwhile</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ActionRules::get_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">) == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_2" class="named-paragraph-link"><span class="named-paragraph">Issue a problem message for a bad parameter</span><span class="named-paragraph-number">11.1.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11">&#167;11</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1" class="paragraph-anchor"></a><b>&#167;11.1.1. </b>All that's left is to issue a "good" problem message, but this is quite a
large undertaking, because the situation as we currently know it is just that
something's wrong with the rule preamble &mdash; which covers an enormous range of
different faults.
</p>

<p class="commentary">The <span class="extract"><span class="extract-syntax">pap_failure_reason</span></span> is a sort of error code set by the action pattern
parser, recording how it most recently failed.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue a problem message for a bad action</span><span class="named-paragraph-number">11.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Bad action pattern: %W = $A\nPAP failure reason: %d\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">, </span><span class="identifier-syntax">ActionRules::get_ap</span><span class="plain-syntax">(</span><span class="identifier-syntax">rcd</span><span class="plain-syntax">), </span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;action-problem-diagnosis&gt;(rfd-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MIXEDNOUNS_PAPF:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_1" class="named-paragraph-link"><span class="named-paragraph">Issue PM_APWithDisjunction problem</span><span class="named-paragraph-number">11.1.1.1</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">NOPARTICIPLE_PAPF:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_2" class="named-paragraph-link"><span class="named-paragraph">Issue PM_APWithNoParticiple problem</span><span class="named-paragraph-number">11.1.1.2</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">IMMISCIBLE_PAPF:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_3" class="named-paragraph-link"><span class="named-paragraph">Issue PM_APWithImmiscible problem</span><span class="named-paragraph-number">11.1.1.3</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">WHEN_PAPF:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_4" class="named-paragraph-link"><span class="named-paragraph">Issue PM_APWithBadWhen problem</span><span class="named-paragraph-number">11.1.1.4</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_5" class="named-paragraph-link"><span class="named-paragraph">Issue PM_APUnknown problem</span><span class="named-paragraph-number">11.1.1.5</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1">&#167;11.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_1" class="paragraph-anchor"></a><b>&#167;11.1.1.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_APWithDisjunction problem</span><span class="named-paragraph-number">11.1.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_APWithDisjunction</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, which seems to introduce a rule, but the circumstances ('%2') seem "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"to be too general for me to understand in a single rule. I can understand a "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"choice of actions, in a list such as 'taking or dropping the ball', but there "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"can only be one set of noun(s) supplied. So 'taking the ball or taking the bat' "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"is disallowed. You can get around this by using named actions ('Taking the ball "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"is being mischievous. Taking the bat is being mischievous. Instead of being "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"mischievous...'), or it may be less bother just to write more than one rule."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1">&#167;11.1.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_2" class="paragraph-anchor"></a><b>&#167;11.1.1.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_APWithNoParticiple problem</span><span class="named-paragraph-number">11.1.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_APWithNoParticiple</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, which seems to introduce a rule taking effect only '%2'. But this "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"does not look like an action, since there is no sign of a participle ending '-ing' "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"(as in 'taking the brick', say) - which makes me think I have badly misunderstood "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"what you intended."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1">&#167;11.1.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_3" class="paragraph-anchor"></a><b>&#167;11.1.1.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_APWithImmiscible problem</span><span class="named-paragraph-number">11.1.1.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_APWithImmiscible</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, which seems to introduce a rule taking effect only '%2'. But this "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"is a combination of actions which cannot be mixed. The only alternatives where "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'or' is allowed are cases where a choice of actions is given but applying to "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"the same objects in each case. (So 'taking or dropping the CD' is allowed, but "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'dropping the CD or inserting the CD into the jewel box' is not, because the "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"alternatives there would make different use of objects from each other.)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1">&#167;11.1.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_4" class="paragraph-anchor"></a><b>&#167;11.1.1.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_APWithBadWhen problem</span><span class="named-paragraph-number">11.1.1.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_APWithBadWhen</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">Q</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">diagnosis</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;action-when-diagnosis&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">Q</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">Q</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;action-when-diagnosis&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">3</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">Q</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;action-when-diagnosis&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">diagnosis</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">Q</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3, </span><span class="string-syntax">"so I am unable to accept this rule."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">diagnosis</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"perhaps because 'nothing' tends not to be allowed in Inform conditions? "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"(Whereas 'no thing' is usually allowed.)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">diagnosis</span><span class="plain-syntax"> == </span><span class="constant-syntax">3</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"perhaps because 'nowhere' tends not to be allowed in Inform conditions? "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"(Whereas 'no room' is usually allowed.)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, which seems to introduce a rule taking effect only '%2'. But this "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"condition did not make sense, %3"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">diagnosis</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"%PIt might be worth mentioning that a 'when' condition tacked on to "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"an action like this is not allowed to mention or use 'called' values."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">diagnosis</span><span class="plain-syntax"> == </span><span class="constant-syntax">4</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"%PThe problem might be that 'and' has been followed by 'when' or 'while'. "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"For example, to make a rule with two conditions, this is okay: 'Instead of "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"jumping when Peter is happy and Peter is in the location'; but the same thing "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"with '...and when Peter is...' is not allowed."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1">&#167;11.1.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_5" class="paragraph-anchor"></a><b>&#167;11.1.1.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_APUnknown problem</span><span class="named-paragraph-number">11.1.1.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax"> == </span><span class="identifier-syntax">WHENOKAY_PAPF</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"The part after 'when' (or 'while') was fine, but the earlier words"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3, </span><span class="string-syntax">"But that"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_APUnknown</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, which seems to introduce a rule taking effect only if the action "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"is '%2'. %3 did not make sense as a description of an action."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_5_1" class="named-paragraph-link"><span class="named-paragraph">See if it starts with a valid action name, at least</span><span class="named-paragraph-number">11.1.1.5.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_5_2" class="named-paragraph-link"><span class="named-paragraph">See if this might be a when-for confusion</span><span class="named-paragraph-number">11.1.1.5.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_5_3" class="named-paragraph-link"><span class="named-paragraph">See if this might be an it-something confusion</span><span class="named-paragraph-number">11.1.1.5.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-rf.html#SP11_1_1_5_4" class="named-paragraph-link"><span class="named-paragraph">Break down the action list and say which are okay</span><span class="named-paragraph-number">11.1.1.5.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">" I am unable to place this rule into any rulebook."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1">&#167;11.1.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_5_1" class="paragraph-anchor"></a><b>&#167;11.1.1.5.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">See if it starts with a valid action name, at least</span><span class="named-paragraph-number">11.1.1.5.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">action_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">an</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">action_name</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">) &lt;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">ActionNameNames::tensed</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">IS_TENSE</span><span class="plain-syntax">))) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">Wordings::match</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Wordings::truncate</span><span class="plain-syntax">(</span><span class="identifier-syntax">ActionNameNames::tensed</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">IS_TENSE</span><span class="plain-syntax">),</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">))))) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">ActionNameNames::tensed</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">IS_TENSE</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">" I notice that there's an action called '%3', though: perhaps this is "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"what you meant?"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1_5">&#167;11.1.1.5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_5_2" class="paragraph-anchor"></a><b>&#167;11.1.1.5.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">See if this might be a when-for confusion</span><span class="named-paragraph-number">11.1.1.5.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax"> == </span><span class="identifier-syntax">WHENOKAY_PAPF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">time_period</span><span class="plain-syntax"> *</span><span class="identifier-syntax">duration</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Occurrence::parse</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">pruned_stem</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">duration</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">Occurrence::used_wording</span><span class="plain-syntax">(</span><span class="identifier-syntax">duration</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">" (I wonder if this might be because '%3', which looks like a condition "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"on the timing, is the wrong side of the 'when...' clause?)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1_5">&#167;11.1.1.5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_5_3" class="paragraph-anchor"></a><b>&#167;11.1.1.5.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">See if this might be an it-something confusion</span><span class="named-paragraph-number">11.1.1.5.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">action_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">an</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">action_name</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ActionNameNames::tensed</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">IS_TENSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ActionSemantics::max_parameters</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            ((</span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">) &gt;= </span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">Wordings::match</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Wordings::truncate</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">, </span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)))))) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">ActionNameNames::tensed</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">IS_TENSE</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">" (I notice that there's an action called '%3': the 'it' in the name "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"is meant to be where something is specified about the first thing "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"it acts on. Try using 'something' rather than 'it'?)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1_5">&#167;11.1.1.5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_1_5_4" class="paragraph-anchor"></a><b>&#167;11.1.1.5.4. </b>If the action pattern contains what looks like a list of action names, as for example
"Instead of taking or dropping the magnet: ..." then the &lt;anl-diagnosis&gt; grammar will
 parse this and return N equal to 2, the apparent number of action names. We then
 run the grammar again, but this time allowing it to print comments on each apparent
 action name it sees.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Break down the action list and say which are okay</span><span class="named-paragraph-number">11.1.1.5.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">issuing_ANL_problem</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">; </span><span class="identifier-syntax">NAP_problem_explained</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;anl-diagnosis&gt;(rfd-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">N</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">positive</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ActionNameLists::parse</span><span class="plain-syntax">(</span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">, </span><span class="identifier-syntax">IS_TENSE</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">positive</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">positive</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">" This looks like a list of actions to avoid: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">" Looking at this as a list of alternative actions: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">issuing_ANL_problem</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">; </span><span class="identifier-syntax">NAP_problem_explained</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="function-syntax">&lt;anl-diagnosis&gt;(rfd-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">defective_ANL_clauses</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span><span class="string-syntax">" but the combination was ambiguous,"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span><span class="string-syntax">" so"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1_1_5">&#167;11.1.1.5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1_2" class="paragraph-anchor"></a><b>&#167;11.1.2. </b>We have a much easier time if the rulebook was value-focused, so that
the only possible problem is that the value was wrong.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue a problem message for a bad parameter</span><span class="named-paragraph-number">11.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">applicability</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_kind</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">pk</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;parametric-problem-diagnosis&gt;(rfd-&gt;</span><span class="element-syntax">pruned_stem</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP11_1">&#167;11.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>And that is the end of the code as such, but we still have to define the
three diagnosis grammars we needed.
</p>

<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>Parametric rules are those applying to values not actions, and the following
is used to choose a problem message if the value makes no sense.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;parametric-problem-diagnosis&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">when</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">play</span><span class="plain-syntax"> </span><span class="identifier-syntax">begins</span><span class="plain-syntax">/</span><span class="identifier-syntax">ends</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13_1" class="paragraph-anchor"></a><b>&#167;13.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_WhenThePlay problem</span><span class="named-paragraph-number">13.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_WhenThePlay</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"there's no scene called 'the play'"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"so I think you need to remove 'the' - Inform has two special rulebooks, 'When "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"play begins' and 'When play ends', and I think you probably mean to refer to "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"one of those."</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP13">&#167;13</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP13_2" class="paragraph-anchor"></a><b>&#167;13.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_BadParameter problem</span><span class="named-paragraph-number">13.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_BadParameter</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, but the description of the thing(s) to which the rule applies ('%2') "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"did not make sense. This is %3 based rulebook, so that should have described %3."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP13">&#167;13</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>And here we choose a problem message if a rule applying to an action is used,
but the action isn't one we recognise.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;action-problem-diagnosis&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">presence</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">in</span><span class="plain-syntax"> ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14_1" class="paragraph-anchor"></a><b>&#167;14.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_NonActionInPresenceOf problem</span><span class="named-paragraph-number">14.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_NonActionInPresenceOf</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, but 'in the presence of...' is a clause which can only be used to "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"talk about an action: so, for instance, 'waiting in the presence of...' is needed. "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"This problem arises especially with 'every turn' rules, where 'every turn in the "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"presence of...' looks plausible but doesn't work. This could be fixed by writing "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'Every turn doing something in the presence of...', but a neater solution talks "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"about the current situation instead: 'Every turn when the player can see...'."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP14">&#167;14</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP14_2" class="paragraph-anchor"></a><b>&#167;14.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_NonActionIn problem</span><span class="named-paragraph-number">14.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_NonActionIn</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"You wrote %1, but 'in...' used in this way should really belong to an action: for "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"instance, 'Before waiting in the Library'. Rules like 'Every turn in the Library' "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"don't work, because 'every turn' is not an action; what's wanted is 'Every turn "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"when in the Library'."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP14">&#167;14</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>The following is used to choose a problem when the trouble with the rule
occurred in a when/while condition at the end; while all five cases produce
the PM_APWithBadWhen problem, they each provide different clues as to what
might have gone wrong.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;action-when-diagnosis&gt;</span>
<span class="plain-syntax">    ... </span><span class="identifier-syntax">called</span><span class="plain-syntax"> ... {</span><span class="identifier-syntax">when</span><span class="plain-syntax">/</span><span class="reserved-syntax">while</span><span class="plain-syntax"> ...} |</span>
<span class="plain-syntax">    ... {</span><span class="identifier-syntax">when</span><span class="plain-syntax">/</span><span class="reserved-syntax">while</span><span class="plain-syntax"> *** </span><span class="identifier-syntax">nothing</span><span class="plain-syntax"> ***} |</span>
<span class="plain-syntax">    ... {</span><span class="identifier-syntax">when</span><span class="plain-syntax">/</span><span class="reserved-syntax">while</span><span class="plain-syntax"> *** </span><span class="identifier-syntax">nowhere</span><span class="plain-syntax"> ***} |</span>
<span class="plain-syntax">    ... </span><span class="identifier-syntax">and</span><span class="plain-syntax"> {</span><span class="identifier-syntax">when</span><span class="plain-syntax">/</span><span class="reserved-syntax">while</span><span class="plain-syntax"> ...} |</span>
<span class="plain-syntax">    ... {</span><span class="identifier-syntax">when</span><span class="plain-syntax">/</span><span class="reserved-syntax">while</span><span class="plain-syntax"> ...}</span>

<span class="function-syntax">&lt;anl-diagnosis&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;anl-inner-diagnosis&gt;</span><span class="plain-syntax"> </span><span class="identifier-syntax">when</span><span class="plain-syntax">/</span><span class="reserved-syntax">while</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;anl-inner-diagnosis&gt;</span>

<span class="function-syntax">&lt;anl-inner-diagnosis&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;anl-entry-diagnosis&gt;</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;anl-tail-diagnosis&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;anl-entry-diagnosis&gt;</span>

<span class="function-syntax">&lt;anl-tail-diagnosis&gt;</span>
<span class="plain-syntax">    , </span><span class="identifier-syntax">_or</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;anl-inner-diagnosis&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">_</span><span class="plain-syntax">,/</span><span class="identifier-syntax">or</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;anl-inner-diagnosis&gt;</span>

<span class="function-syntax">&lt;anl-entry-diagnosis&gt;</span>
<span class="plain-syntax">    ......</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15_1" class="paragraph-anchor"></a><b>&#167;15.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Diagnose problem with this ANL entry</span><span class="named-paragraph-number">15.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">issuing_ANL_problem</span><span class="plain-syntax">) &amp;&amp; (!</span><span class="identifier-syntax">preform_lookahead_mode</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">defective_ANL_clauses</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(4, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;action-pattern&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span><span class="string-syntax">"'%4' did not make sense; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ap</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">form</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">APClauses::is_request</span><span class="plain-syntax">(</span><span class="identifier-syntax">ap</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">"'%4' would make sense as an action on its own, but 'or' can't "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"be used in combination with 'asking... to try...' actions; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>

<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ActionPatterns::refers_to_past</span><span class="plain-syntax">(</span><span class="identifier-syntax">ap</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">"'%4' would make sense as an action on its own, but 'or' can't "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"be used in combination with actions with time periods attached; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;named-action-pattern&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NAP_problem_explained</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                    </span><span class="string-syntax">"'%4' only made sense as a named kind of action, which can "</span>
<span class="plain-syntax">                    </span><span class="string-syntax">"be used on its own but not in an action list; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                    </span><span class="string-syntax">"'%4' is another named kind of action; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">NAP_problem_explained</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">form</span><span class="plain-syntax"> == </span><span class="identifier-syntax">ACTOR_EXP_PLAYER</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">"'%4' would have been okay except for using the word 'trying', "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"which isn't allowed in a list like this; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">defective_ANL_clauses</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span><span class="string-syntax">"'%4' was okay; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    ==&gt; { </span><span class="constant-syntax">1</span><span class="plain-syntax">, - };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-rf.html#SP15">&#167;15</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. Compilation.</b>The actual compilation of rules is done elsewhere; here we simply make sure
that rule bodies won't be accidentally compiled as if they were phrase bodies.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::compile</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::compile</span></span>:<br/><a href="5-rf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">self</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> *</span><span class="identifier-syntax">total_phrases_compiled</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">total_phrases_to_compile</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">, </span><span class="reserved-syntax">rule</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">defn_as_I7_source</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">defn_as_I7_source</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">body_of_defn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">compilation_data</span><span class="plain-syntax">.</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">at_least_one_compiled_form_needed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><a href="6-rls.html#SP16" class="function-link"><span class="function-syntax">Rules::check_constraints_are_typesafe</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. Miscellaneous access functions.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::get_prewhile_text</span><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family</span><span class="plain-syntax"> != </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">prewhile_applicability</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::get_rulebook_placement</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::get_rulebook_placement</span></span>:<br/>Rule Bookings - <a href="6-rb.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family</span><span class="plain-syntax"> != </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">MIDDLE_PLACEMENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook_placement</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">rulebook</span><span class="plain-syntax"> *</span><span class="function-syntax">RuleFamily::get_rulebook</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::get_rulebook</span></span>:<br/>Rule Bookings - <a href="6-rb.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family</span><span class="plain-syntax"> != </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::set_rulebook</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::set_rulebook</span></span>:<br/>Rule Bookings - <a href="6-rb.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="reserved-syntax">rulebook</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rb</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family</span><span class="plain-syntax"> != </span><span class="identifier-syntax">rule_idf</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"cannot set rulebook: not a rule"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rule_family_data</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rfd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_rule_family_data</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">family_specific_data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rfd</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_rulebook</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rb</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">RuleFamily::allows_rule_only</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">RuleFamily::allows_rule_only</span></span>:<br/><a href="5-rf.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">imperative_defn_family</span><span class="plain-syntax"> *</span><span class="identifier-syntax">self</span><span class="plain-syntax">, </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="5-po.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-am.html">1</a></li><li class="progresschapter"><a href="2-bv.html">2</a></li><li class="progresschapter"><a href="3-dlr.html">3</a></li><li class="progresschapter"><a href="4-nr.html">4</a></li><li class="progresscurrentchapter">5</li><li class="progresssection"><a href="5-id.html">id</a></li><li class="progresssection"><a href="5-idf.html">idf</a></li><li class="progresssection"><a href="5-adf.html">adf</a></li><li class="progresssection"><a href="5-tpf.html">tpf</a></li><li class="progresssection"><a href="5-ptd.html">ptd</a></li><li class="progresssection"><a href="5-ptd2.html">ptd2</a></li><li class="progresssection"><a href="5-po.html">po</a></li><li class="progresscurrent">rf</li><li class="progresssection"><a href="5-rcd.html">rcd</a></li><li class="progresschapter"><a href="6-rls.html">6</a></li><li class="progresschapter"><a href="7-tc.html">7</a></li><li class="progresschapter"><a href="8-kpr.html">8</a></li><li class="progressnext"><a href="5-rcd.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

